package com.c.ctgproject.adapter.guang

import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.databinding.ItemCarInPartCountListBinding
import com.c.ctgproject.entity.guang.DictionaryChildBean
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.wiget.NumberAddSubLayout


class CarInPartCountAdapter(private val context: Context, private val mList: List<DictionaryChildBean>) : RecyclerView.Adapter<CarInPartCountAdapter.MyViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view = ItemCarInPartCountListBinding.inflate(LayoutInflater.from(context), parent, false)
        return MyViewHolder(view)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val data = mList[position]
        holder.mNameTV.text = data.key.handlerNull()
        //holder.couplingMotorET.textSet(data.count.handlerNull())
        holder.couplingMotorET.setText(data.count.handlerNull())
        holder.couplingMotorET.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

            }

            override fun afterTextChanged(s: Editable?) {
                    data.count=s.handlerNull()
                //notifyItemChanged(holder.adapterPosition)
            }

        })
//        holder.couplingMotorET.addListener(object:NumberAddSubLayout.NumberAddSubLayoutListener{
//            override fun onCountChange(count: String) {
//                data.count=count
////                notifyItemChanged(holder.adapterPosition)
//            }
//        })
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    inner class MyViewHolder(view: ItemCarInPartCountListBinding) : RecyclerView.ViewHolder(view.root) {
        val couplingMotorET = view.couplingMotorET
        val mNameTV = view.mNameTV
    }
}
